<?php
    use User\Model\NiudanModel;
?>
<style>
    .picurl{opacity:0;width:50px;height:50px;background-color:red;float:left}
    .picimg{width:50px;height:50px;float:left;margin-left:-50px}
</style>
<div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                扭蛋 - <if condition="$id eq -1">新建<else/>编辑</if>
            </header>
            <div class="panel-body">
                <form class="form-horizontal" method="post" action="/User/Niudan/update" enctype="multipart/form-data" onsubmit="return checkNiudan();">
                    <input type="hidden" name="id" value="{$id}">
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>活动名称</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control required" title="请填写活动名称" name="title" value="{$niudan['title']}">
                        </div>
                        <input type="file" class="picurl" name="picurl1" data-action="uploadFile1">
                        <if condition="$niudan.picurl neq null">
                            <input type="hidden" name="picurl1" value="{$niudan['picurl']}" data-set="uploadFile1">
                        </if>
                        <img src="{$niudan['picurl']}" class="picimg" data-preview="uploadFile1">
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>活动时间</label>
                        <div class="col-lg-3">
                            <input class="form-control required" title="请填写开始时间" id="date-picker1" name="start_date" value="{$niudan['startdate']}" placeholder="开始时间">
                        </div>
                        <div class="col-lg-3">
                            <input class="form-control required" title="请填写结束时间" id="date-picker2" name="end_date" value="{$niudan['enddate']}" placeholder="结束时间">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-2 col-sm-2 control-label">活动说明</div>
                        <div class="col-lg-6">
                            <textarea id="editor-container" name="info" style="width:600px;height:300px;"></textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>每日中奖次数上限</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control required" title="每日中奖次数上限" name="number_limits" value="{$niudan['number_limits']}">
                            <p class="help-block">如若忽略，请填-1</p>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>每人中奖次数</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control required" title="每人中奖次数" name="per_num_sum" value="{$niudan['per_num_sum']}">
                            <p class="help-block">如若忽略，请填-1</p>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>每人每日游戏次数上限</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control required" title="每人每日游戏次数上限" name="per_num" value="{$niudan['per_num']}">
                            <p class="help-block">如若忽略，请填-1</p>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">分享奖励次数</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="share_play" value="{$niudan['share_play']}">
                        </div>
                    </div>

                    <!--<div class="form-group">-->
                        <!--<label class="col-sm-2 col-sm-2 control-label">邀请奖励次数</label>-->
                        <!--<div class="col-lg-6">-->
                            <!--<input type="text" class="form-control" name="invite_play" value="{$niudan['invite_play']}">-->
                        <!--</div>-->
                    <!--</div>-->

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">联系地址</label>
                        <div class="col-sm-10">
                            <input type="radio" name="address" value="<?php echo NiudanModel::ADDRESS_NO?>"
                                <if condition="($id eq -1) or ($niudan['address'] eq NiudanModel::ADDRESS_NO)">checked</if>>否&nbsp;&nbsp;
                            <input type="radio" name="address" value="<?php echo NiudanModel::ADDRESS_YES?>"
                                <if condition="$niudan['address'] eq NiudanModel::ADDRESS_YES">checked</if>>是
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">强制关注</label>
                        <div class="col-sm-10">
                            <input type="radio" name="follow" value="<?php echo NiudanModel::FOLLOW_NO?>"
                                <if condition="($id eq -1) or ($niudan['follow'] eq NiudanModel::FOLLOW_NO)">checked</if>
                                onclick="$('.follow_qrImage').hide()">否&nbsp;&nbsp;
                            <input type="radio" name="follow" value="<?php echo NiudanModel::FOLLOW_YES?>"
                                <if condition="$niudan['follow'] eq NiudanModel::FOLLOW_YES">checked</if>
                                onclick="$('.follow_qrImage').show()">是
                        </div>
                    </div>

                    <div class="form-group follow_qrImage" <if condition="$niudan['follow'] eq NiudanModel::FOLLOW_NO">
                        style="display:none"</if>>
                        <label class="col-sm-2 col-sm-2 control-label">分享按钮</label>
                        <div class="col-lg-6">
                            <img src="{$niudan['follow_qrImage']}" style="width:100px;height:100px" data-preview="uploadFile2">
                            <input type="file" name="picurl2" data-action="uploadFile2">
                            <if condition="$niudan.follow_qrImage neq null">
                                <input type="hidden" name="picurl2" value="{$niudan['follow_qrImage']}" data-set="uploadFile2">
                            </if>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-10">
                            <button class="btn btn-primary" type="submit" id="submit">提交</button>
                            <button class="btn btn-default" type="button" onclick="history.back(-1);">取消</button>
                        </div>
                    </div>
                </form>
            </div>
        </section>
    </div>
</div>
<script type="text/javascript" charset="utf-8" src="/Public/js/common/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/Public/js/common/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/Public/js/common/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/Public/js/laydatenew/laydate.js"></script>
<script type="text/javascript" src="/Public/js/common.upload.js"></script>
<script type="text/javascript">
    common.upload.img.init();
    laydate.render({
        elem: '#date-picker1',
        type: 'datetime'
    });
    laydate.render({
        elem: '#date-picker2',
        type: 'datetime'
    });
    var editor = UE.getEditor('editor-container');
    var content = '<?php if(empty($niudan["info"])){echo "";}else{ echo $niudan["info"];}?>';
    editor.addListener("ready", function () {
        editor.setContent(content);
    });

    function checkNiudan(){
        var ret = true;
        $(".required").each(function(){
            if($(this).val() == ""){
                alert($(this).attr("title"));
                ret = false;
                return false;
            }
        })
        return ret;
    }
</script>